using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;
using NetProtocol.Client;
using NetProtocol.POD;

namespace IQIGame.Onigao.GamePlay
{
    public class ChatModule : Singleton<ChatModule>, CNetCenterChat
    {
        private ChatModule() { }
        public static CNetCenterChat NetCore => Instance;
        ISession CNetCenterChat.GetSession()
        {
            return GameServerModule.Instance.CurrSession;
        }

        void CNetCenterChat.SC_notifyChat(ISession session, SChatPOD chat)
        {
            //TODO:聊天UI逻辑

            #region 回收pod, 最后执行
            if (chat.sender != null)
            {
                PODPool<PlayerSimplePOD>.Put(chat.sender);
            }
            PODPool<SChatPOD>.Put(chat);
            #endregion
        }

        void CNetCenterChat.SC_notifyChatRoom(ISession session, ChatRoomPOD chatRoom)
        {
            //TODO:聊天室逻辑
            if (chatRoom == null)
            {
                return;
            }

            #region 回收pod, 最后执行
            foreach (var chat in chatRoom.msg)
            {
                if (chat.sender != null)
                {
                    PODPool<PlayerSimplePOD>.Put(chat.sender);
                }
                PODPool<SChatPOD>.Put(chat);
            }
            #endregion
        }
    }

}
